import Vue from "vue";
import VueRouter from "vue-router";

// 引入子组件
import Home from "@/views/Home";
import About from "@/views/About";
import Message from "@/views/Message";
import News from "@/views/News";
import Internet from "@/views/Internet"

Vue.use(VueRouter);// 安装插件
// 两个内置全局组件：router-link 和 router-view (RouterLink 和 RouterView)

const router = new VueRouter({
  mode: "history", //路由的模式 （history和hash）
  routes: [ //路由配置项
    {
      path: "/home",  //路由路径
      component: Home, //路由组件
      name: "Home",
      redirect:"/home/news",// 重定向地址
      children: [
        {
          path: "/home/message",  
          component: Message, 
          name: "Message"
        },
        {
          path: "news", // 路径简写：自动补全父路由路径 -> /home/news 
          component: News, 
          name:'News',
        },
      ],
    },
    {
      path: "/about",  //路由路径
      component: About, //路由组件
      redirect: "/about/internet",
      children: [
        {
          path: "internet",
          component: Internet,
          name: "Internet",
          meta: {
            name: "jack",
            age: 18,
          }
        },
      ],
    },
    {
      path: "*",  
      redirect: "/home",
    },
  ],
});

export default router;